/**
 * @file SIPServer.hpp
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief SIP服务器
 * @version 0.0.1
 * @date 2020-07-16
 * 
 * @coryright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#pragma once
#include <string>
#include "eXosip2/eXosip.h"
#include "defs.hpp"
#include "STL_SafeQueue.hpp"
#include "EventMgr.hpp"

class SIPServer
{
public:
    SIPServer();

    ~SIPServer();

    static SIPServer *instance();

    void init();

    void setLocalConfig(const std::string &sip_id, const std::string &host, uint16_t port);

    void start(const std::string &user_agent);

    void quit();

    eXosip_t *GetExosipContext()
    {
        return m_excontext;
    }

public:
    int DoReceiveEvents();

    int DoProcessEvents();

private:
    sip_event_sptr new_event(eXosip_t *exosip_context, eXosip_event_t *exosip_event);

private:
    uint16_t m_sipPort;
    uint64_t m_eventId;
    std::string m_sipId;
    std::string m_sipHost;
    eXosip_t *m_excontext;
    stl::SafeQueue<sip_event_sptr> m_eventQueue;
    EventMgr m_eventHandle;
};